#include "EngineHeader.h"
#include "GraphicsHeader.h"

namespace LSH
{
namespace Graphics
{

IMPLEMENT_SINGLETON(TextureManager);


//------------------------------------------------------------------------------
TextureManager::TextureManager(void)
{
}

//------------------------------------------------------------------------------
TextureManager::~TextureManager(void)
{
    _destory();
}

//------------------------------------------------------------------------------
Texture* TextureManager::loadTextureFormFile(String& fileName)
{
    Texture* pTexture = NULL;
    textureItr itr = _textures.find(fileName);
    if(itr == _textures.end())
    {
       pTexture = CM_NEW(Texture);
       if(FALSE == pTexture->loadFormFile(fileName))
       {
           CM_DELETE(pTexture);
           return NULL;
       }
    }
    return pTexture;
}

//------------------------------------------------------------------------------
void TextureManager::freeTexture(Texture* pTexture)
{
}

//------------------------------------------------------------------------------
void TextureManager::_destory()
{
   if(false == _textures.empty())
   {
       textureItr itr = _textures.begin();
       textureItr itrEnd = _textures.end();
       while(itr != itrEnd)
       {
           delete(itr->second);
           itr++;
       }
       _textures.clear();
   }
}

}
}

